﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FileManagerSystem.Models
{
    /// <summary>
    /// 返回JSON数据统一实体
    /// </summary>
    public class JsonDataModel
    {
        public JsonDataModel()
        {
            code = 0;
            msg = "请求成功";
        }

        /// <summary>
        /// 请求返回码
        /// 0.为成功
        /// 其他数值为不成功
        /// </summary>
        public int code { get; set; }

        /// <summary>
        /// 请求返回信息
        /// </summary>
        public string msg { get; set; } = "请求成功";

        /// <summary>
        /// 请求返回数据
        /// </summary>
        public object data { get; set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="obj">数据集合</param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static JsonDataModel Ok(object obj, string message = null)
        {
            return new JsonDataModel() { code = 0, msg = message ?? "请求成功", data = obj };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="message">失败信息</param>
        /// <param name="code">错误代码 默认-1</param>
        /// <returns></returns>
        public static JsonDataModel Error(string message = null, int code = -1)
        {
            return new JsonDataModel() { code = code, msg = message ?? "请求失败" };
        }
    }
}
